package cn.bjit.controller;


import cn.bjit.controller.request.AccountLoginRequest;
import cn.bjit.controller.request.AccountRegisterRequest;
import cn.bjit.enums.BizCodeEnum;
import cn.bjit.service.AccountService;
import cn.bjit.service.FileService;
import cn.bjit.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2022-07-29
 */
@RestController
@RequestMapping("/api/account/v1")
public class AccountController {
    @Autowired
    private FileService fileService;

    @Autowired
    private AccountService accountService;

    /**
     * 登录
     * @param accountLoginRequest
     * @return
     */
    @PostMapping("login")
    public JsonData login(@RequestBody AccountLoginRequest accountLoginRequest){
        JsonData jsonData=accountService.login(accountLoginRequest);
        return jsonData;
    }


    /**
     * 注册
     * @param accountRegisterRequest
     * @return
     */
    @PostMapping("register")
    public JsonData register(@RequestBody AccountRegisterRequest accountRegisterRequest){
       JsonData jsonData= accountService.register(accountRegisterRequest);
        return  jsonData;
    }


    /**
     * 上传头像
     * @param file
     * @return
     */
    @PostMapping("upload")
    public JsonData uploadUserImg(@RequestPart("file")MultipartFile file){
      String result=  fileService.uploadUserImg(file);
        return result!=null?JsonData.buildSuccess(result):JsonData.buildResult(BizCodeEnum.FILE_UPLOAD_USER_IMG_FAIL);
    }

}

